Accept more templates in service fields#150239
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
0561931 to
faa2402
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for using dynamic templates that evaluate to lists directly in target service fields (area_id, device_id, floor_id, label_id), without requiring a mixed list syntax. Previously, only entity_id supported this pattern where a single template could return a list.
Key Changes
- Extended the
_TARGET_SERVICE_FIELDS_TEMPLATEDschema to allowdynamic_templateas a standalone option forarea_id,device_id,floor_id, andlabel_idfields - Added test coverage for the new functionality showing templates that evaluate to lists (e.g.,
"{{ ['area-42', 'area-51'] }}")
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/helpers/config_validation.py |
Added dynamic_template as a valid schema option for target service fields (ATTR_DEVICE_ID, ATTR_AREA_ID, ATTR_FLOOR_ID, ATTR_LABEL_ID) to allow templates that return lists |
tests/helpers/test_service.py |
Added test case verifying that templates evaluating to lists work correctly for all target fields |
emontnemery
left a comment
There was a problem hiding this comment.
LGTM, thanks @arturpragacz 👍
Proposed change
The templated initial schema was made to allow templates also on the level of individual keys.
Currently both of the following work correctly:
but the following fails:
This PR fixes that problem.
Alternative to #149911.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: